package com.yanqu.road.dao.impl.activity.springdraw;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.activity.daomu.config.DaoMuCaptainConfig;
import com.yanqu.road.entity.activity.springdraw.config.SpringDrawConfig;
import com.yanqu.road.entity.activity.springdraw.config.SpringDrawDigRewardConfig;
import com.yanqu.road.utils.property.PropertyHelper;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.HashMap;
import java.util.Map;

public class SpringDrawConfigDaoImpl extends TempDao {

    /**
     * 查询奖励配置
     */
    private static String getDigRewardSql = "select * from `t_s_activity_dig_reward` where `activityId`= ?";
    public Map<Integer, SpringDrawDigRewardConfig> getConfig(int activityId) {
        Map<Integer, SpringDrawDigRewardConfig> map = new HashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getDigRewardSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                SpringDrawDigRewardConfig info = new SpringDrawDigRewardConfig();
                info.setActivityId(rs.getInt("activityId"));
                info.setLevel(rs.getInt("level"));
                info.setCost(rs.getInt("cost"));
                info.setRewardList(rs.getString("rewardList"));
                info.parsePassReward();
                info.setIsReview(rs.getInt("isReview"));
                info.setReward1(rs.getString("reward1"));
                info.setReward2(rs.getString("reward2"));
                info.setReward3(rs.getString("reward3"));
                info.setReward4(rs.getString("reward4"));
                info.setReward5(rs.getString("reward5"));
                info.setReward6(rs.getString("reward6"));
                info.setReward7(rs.getString("reward7"));
                info.setReward8(rs.getString("reward8"));
                info.setReward9(rs.getString("reward9"));
                info.setReward10(rs.getString("reward10"));
                info.setReward11(rs.getString("reward11"));
                info.setReward1Property(PropertyHelper.parseStringToProperty(info.getReward1()));
                info.setReward2Property(PropertyHelper.parseStringToProperty(info.getReward2()));
                info.setReward3Property(PropertyHelper.parseStringToProperty(info.getReward3()));
                info.setReward4Property(PropertyHelper.parseStringToProperty(info.getReward4()));
                info.setReward5Property(PropertyHelper.parseStringToProperty(info.getReward5()));
                info.setReward6Property(PropertyHelper.parseStringToProperty(info.getReward6()));
                info.setReward7Property(PropertyHelper.parseStringToProperty(info.getReward7()));
                info.setReward8Property(PropertyHelper.parseStringToProperty(info.getReward8()));
                info.setReward9Property(PropertyHelper.parseStringToProperty(info.getReward9()));
                info.setReward10Property(PropertyHelper.parseStringToProperty(info.getReward10()));
                info.setReward11Property(PropertyHelper.parseStringToProperty(info.getReward11()));
                map.put(info.getLevel(), info);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return map;
    }
}
